import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

class DismissibleTestApp extends StatelessWidget {
  List<String> items = List<String>.generate(100,(index){
    return "$index-Item";
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(

      body: ListView.builder(
        scrollDirection: Axis.vertical,
        itemCount: items.length,
        itemBuilder: (context,index){
          return  Dismissible(
            key: GlobalKey(debugLabel:  index.toString()),
            direction: DismissDirection.horizontal,
            //crossAxisEndOffset:200.0,
            dismissThresholds:{DismissDirection.endToStart:1.5},
            dragStartBehavior:DragStartBehavior.start,
              // direction: DismissDirection.endToStart,
            onDismissed: (direction){
              print(direction.index);
              SnackBar snackBar= SnackBar(content:
                  Text('项目已经删除$direction.index')
              );
              Scaffold.of(context).showSnackBar(snackBar);
            },
            confirmDismiss: (direction){
              return new Future.value(true);
            },
            child: ListTile(
              leading: Icon(Icons.library_add),
              subtitle: Text('这是子标题-$index'),
              title:Text("这是标题"),
              isThreeLine: true,
            ),
            background: Container(
              color: Colors.blueAccent[200],
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  Container(
                    child: Text('删除'),
                  ),
                  Container(
                    child: Text('收藏'),
                  )
                ],
              ),
            ),
              secondaryBackground: Container(
                color: Colors.blueAccent[200],
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[
                    Container(
                      child: Text('测试01'),
                    ),
                    Container(
                      child: Text('测试02'),
                    )
                  ],
                ),
              ),
          );
        },
      ),
    );
  }
}
